#include "htr32xx.h"
#include "options.h"
#include "resources.h"
#include "soft_timer.h"
#include "storage.h"

/*---------- macro ----------*/
#define TAG "app_htr3218"

/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/
/*---------- variable ----------*/
static void* proc_timer;
static void* htr321x;
static struct storage_led_struct* storage_led = NULL;
/*---------- function ----------*/
#define Light_Grade 25
#define LED_NUM 18
static uint8_t Marquee_Reset = 1;
static uint8_t Marquee_Start_Num = 0; //
static uint8_t Led_Duty[LED_NUM] = { 0 };
static uint8_t Led_Duty_update[LED_NUM] = { 0 };
static uint8_t Led_Duty_Up_Down[LED_NUM] = { 0 };
static volatile uint8_t Current_num = 0;
void Led_Marquee(void) {
    if (Marquee_Reset) {
        Marquee_Reset = 0;
        Current_num = Marquee_Start_Num;
        memset(Led_Duty, 0, LED_NUM);
        memset(Led_Duty_Up_Down, 0, LED_NUM);
        Led_Duty_Up_Down[Current_num] = 1;
    }
    for (int i = 0; i < LED_NUM; i++) {
        if (Led_Duty_Up_Down[i] == 1) {
            if (Led_Duty[i] < (0xFF - Light_Grade))
                Led_Duty[i] += Light_Grade;
            else {
                Led_Duty[i] = 0xFF;
                Led_Duty_Up_Down[i] = 0;
            }
            if (Led_Duty[i] == Light_Grade * 100 / 20) {
                Current_num = (Current_num == (LED_NUM - 1)) ? 0 : Current_num + 1;
                Led_Duty_Up_Down[Current_num] = 1;
            }
        }
        else //
        {
            if (Led_Duty[i] != 0) {
                if (Led_Duty[i] >= 12)
                    Led_Duty[i] -= 12;
                else
                    Led_Duty[i] = 0;
            }
        }
    }
}
static void reback_led_sta(uint8_t led_num) {
    storage_led = (struct storage_led_struct*)storage_get(STORAGE_AREA_LIGHT_MODE);
    assert(storage_led);
    if (storage_led->led_mode == full_bright)
    {
        if (led_num == LED_NUM) {
            memset(Led_Duty_update, 255, LED_NUM);
            device_write(htr321x, Led_Duty_update, HTR32xx_LED0, LED_NUM);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            Led_Duty[0] = 255;
            device_write(htr321x, &Led_Duty[0], led_num, 1);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
    }
    else if (storage_led->led_mode == mid_bright)
    {
        if (led_num == LED_NUM) {
            memset(Led_Duty_update, 2.5 * _led_value_mid, LED_NUM);
            device_write(htr321x, &Led_Duty_update, HTR32xx_LED0, LED_NUM);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            Led_Duty[0] = 2.5 * _led_value_mid;
            device_write(htr321x, &Led_Duty[0], led_num, 1);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
    }
    else if (storage_led->led_mode == low_bright)
    {
        if (led_num == LED_NUM) {
            memset(Led_Duty_update, 2.5 * _led_value_min, LED_NUM);
            device_write(htr321x, &Led_Duty_update, HTR32xx_LED0, LED_NUM);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            Led_Duty[0] = 2.5 * _led_value_min;
            device_write(htr321x, &Led_Duty[0], led_num, 1);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
    }
    else if (storage_led->led_mode == die_bright)
    {
        if (led_num == LED_NUM) {
            memset(Led_Duty_update, 0, LED_NUM);
            device_write(htr321x, Led_Duty_update, HTR32xx_LED0, LED_NUM);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            Led_Duty[0] = 0;
            device_write(htr321x, &Led_Duty[0], led_num, 1);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
    }
    else if (storage_led->led_mode == no_spuse)
    {
        if (led_num == LED_NUM) {
            memset(Led_Duty_update, storage_led->assign_bright, LED_NUM);
            device_write(htr321x, Led_Duty_update, HTR32xx_LED0, LED_NUM);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            Led_Duty[0] = storage_led->assign_bright;
            device_write(htr321x, &Led_Duty[0], led_num, 1);
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
    }
}
htr32xx_argument htr3218_ops;
static void _timer_expired(timer_handle_t timer) {
    uint8_t die_ledmoded_ledvule = 255;
    static char cflag_ = 0, cflag_times = 0;
    if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_START) {
        if (cflag_ == 0) {
            memset(Led_Duty, 255, LED_NUM);
            device_write(htr321x, Led_Duty, HTR32xx_LED0, LED_NUM);
            cflag_ = 1;
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
        }
        else {
            memset(Led_Duty, 0, LED_NUM);
            device_write(htr321x, Led_Duty, HTR32xx_LED0, LED_NUM);
            cflag_ = 0;
            device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            cflag_times++;
        }
        if (cflag_times >= 8) {
            cflag_ = 0;
            cflag_times = 0;
            no_storage.led_temp_variable.dev_work_mode = LED_MODE_UPDATA;
        }
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_CLEAN) {
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_LOCAL) {
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_UPDATA) {
        reback_led_sta(LED_NUM);
        no_storage.led_temp_variable.dev_work_mode = LED_MODE_WORK;
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_WORK) {
        if (storage_led->assign_bright == 0)
            die_ledmoded_ledvule = 255;
        else
            die_ledmoded_ledvule = storage_led->assign_bright;

        if (no_storage.led_temp_variable.led1_push == 1) {
            if (no_storage.led_temp_variable.led1_toogle_flag == 0) {
                Led_Duty[0] = 0;
                device_write(htr321x, &Led_Duty[0], HTR32xx_LED0, 1);
                no_storage.led_temp_variable.led1_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[0] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[0], HTR32xx_LED0, 1);
                no_storage.led_temp_variable.led1_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led1_blink_times++;
            }
            if (no_storage.led_temp_variable.led1_blink_times >= 8) {
                no_storage.led_temp_variable.led1_blink_times = 0;
                no_storage.led_temp_variable.led1_toogle_flag = 0;
                no_storage.led_temp_variable.led1_push = 0;
                reback_led_sta(0);
            }
        }
        if (no_storage.led_temp_variable.led2_push == 1) {
            if (no_storage.led_temp_variable.led2_toogle_flag == 0) {
                Led_Duty[1] = 0;
                device_write(htr321x, &Led_Duty[1], HTR32xx_LED1, 1);
                no_storage.led_temp_variable.led2_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[1] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[1], HTR32xx_LED1, 1);
                no_storage.led_temp_variable.led2_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led2_blink_times++;
            }
            if (no_storage.led_temp_variable.led2_blink_times >= 8) {
                no_storage.led_temp_variable.led2_blink_times = 0;
                no_storage.led_temp_variable.led2_toogle_flag = 0;
                no_storage.led_temp_variable.led2_push = 0;
                reback_led_sta(1);
            }
        }
        if (no_storage.led_temp_variable.led3_push == 1) {
            if (no_storage.led_temp_variable.led3_toogle_flag == 0) {
                Led_Duty[2] = 0;
                device_write(htr321x, &Led_Duty[2], HTR32xx_LED2, 1);
                no_storage.led_temp_variable.led3_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[2] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[2], HTR32xx_LED2, 1);
                no_storage.led_temp_variable.led3_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led3_blink_times++;
            }
            if (no_storage.led_temp_variable.led3_blink_times >= 8) {
                no_storage.led_temp_variable.led3_blink_times = 0;
                no_storage.led_temp_variable.led3_toogle_flag = 0;
                no_storage.led_temp_variable.led3_push = 0;
                reback_led_sta(2);
            }
        }
        if (no_storage.led_temp_variable.led4_push == 1) {
            if (no_storage.led_temp_variable.led4_toogle_flag == 0) {
                Led_Duty[3] = 0;
                device_write(htr321x, &Led_Duty[3], HTR32xx_LED3, 1);
                no_storage.led_temp_variable.led4_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[3] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[3], HTR32xx_LED3, 1);
                no_storage.led_temp_variable.led4_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led4_blink_times++;
            }
            if (no_storage.led_temp_variable.led4_blink_times >= 8) {
                no_storage.led_temp_variable.led4_blink_times = 0;
                no_storage.led_temp_variable.led4_toogle_flag = 0;
                no_storage.led_temp_variable.led4_push = 0;
                reback_led_sta(3);
            }
        }
        if (no_storage.led_temp_variable.led5_push == 1) {
            if (no_storage.led_temp_variable.led5_toogle_flag == 0) {
                Led_Duty[4] = 0;
                device_write(htr321x, &Led_Duty[4], HTR32xx_LED4, 1);
                no_storage.led_temp_variable.led5_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[4] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[4], HTR32xx_LED4, 1);
                no_storage.led_temp_variable.led5_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led5_blink_times++;
            }
            if (no_storage.led_temp_variable.led5_blink_times >= 8) {
                no_storage.led_temp_variable.led5_blink_times = 0;
                no_storage.led_temp_variable.led5_toogle_flag = 0;
                no_storage.led_temp_variable.led5_push = 0;
                reback_led_sta(4);
            }
        }
        if (no_storage.led_temp_variable.led6_push == 1) {
            if (no_storage.led_temp_variable.led6_toogle_flag == 0) {
                Led_Duty[5] = 0;
                device_write(htr321x, &Led_Duty[5], HTR32xx_LED5, 1);
                no_storage.led_temp_variable.led6_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[5] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[5], HTR32xx_LED5, 1);
                no_storage.led_temp_variable.led6_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led6_blink_times++;
            }
            if (no_storage.led_temp_variable.led6_blink_times >= 8) {
                no_storage.led_temp_variable.led6_blink_times = 0;
                no_storage.led_temp_variable.led6_toogle_flag = 0;
                no_storage.led_temp_variable.led6_push = 0;
                reback_led_sta(5);
            }
        }
        if (no_storage.led_temp_variable.led7_push == 1) {
            if (no_storage.led_temp_variable.led7_toogle_flag == 0) {
                Led_Duty[6] = 0;
                device_write(htr321x, &Led_Duty[6], HTR32xx_LED6, 1);
                no_storage.led_temp_variable.led7_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[6] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[6], HTR32xx_LED6, 1);
                no_storage.led_temp_variable.led7_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led7_blink_times++;
            }
            if (no_storage.led_temp_variable.led7_blink_times >= 8) {
                no_storage.led_temp_variable.led7_blink_times = 0;
                no_storage.led_temp_variable.led7_toogle_flag = 0;
                no_storage.led_temp_variable.led7_push = 0;
                reback_led_sta(6);
            }
        }
        if (no_storage.led_temp_variable.led8_push == 1) {
            if (no_storage.led_temp_variable.led8_toogle_flag == 0) {
                Led_Duty[7] = 0;
                device_write(htr321x, &Led_Duty[7], HTR32xx_LED7, 1);
                no_storage.led_temp_variable.led8_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[7] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[7], HTR32xx_LED7, 1);
                no_storage.led_temp_variable.led8_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led8_blink_times++;
            }
            if (no_storage.led_temp_variable.led8_blink_times >= 8) {
                no_storage.led_temp_variable.led8_blink_times = 0;
                no_storage.led_temp_variable.led8_toogle_flag = 0;
                no_storage.led_temp_variable.led8_push = 0;
                reback_led_sta(7);
            }
        }
        if (no_storage.led_temp_variable.led9_push == 1) {
            if (no_storage.led_temp_variable.led9_toogle_flag == 0) {
                Led_Duty[8] = 0;
                device_write(htr321x, &Led_Duty[8], HTR32xx_LED8, 1);
                no_storage.led_temp_variable.led9_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[8] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[8], HTR32xx_LED8, 1);
                no_storage.led_temp_variable.led9_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led9_blink_times++;
            }
            if (no_storage.led_temp_variable.led9_blink_times >= 8) {
                no_storage.led_temp_variable.led9_blink_times = 0;
                no_storage.led_temp_variable.led9_toogle_flag = 0;
                no_storage.led_temp_variable.led9_push = 0;
                reback_led_sta(8);
            }
        }
        if (no_storage.led_temp_variable.led10_push == 1) {
            if (no_storage.led_temp_variable.led10_toogle_flag == 0) {
                Led_Duty[9] = 0;
                device_write(htr321x, &Led_Duty[9], HTR32xx_LED9, 1);
                no_storage.led_temp_variable.led10_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[9] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[9], HTR32xx_LED9, 1);
                no_storage.led_temp_variable.led10_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led10_blink_times++;
            }
            if (no_storage.led_temp_variable.led10_blink_times >= 8) {
                no_storage.led_temp_variable.led10_blink_times = 0;
                no_storage.led_temp_variable.led10_toogle_flag = 0;
                no_storage.led_temp_variable.led10_push = 0;
                reback_led_sta(9);
            }
        }
        if (no_storage.led_temp_variable.led11_push == 1) {
            if (no_storage.led_temp_variable.led11_toogle_flag == 0) {
                Led_Duty[10] = 0;
                device_write(htr321x, &Led_Duty[10], HTR32xx_LED10, 1);
                no_storage.led_temp_variable.led11_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[10] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[10], HTR32xx_LED10, 1);
                no_storage.led_temp_variable.led11_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led11_blink_times++;
            }
            if (no_storage.led_temp_variable.led11_blink_times >= 8) {
                no_storage.led_temp_variable.led11_blink_times = 0;
                no_storage.led_temp_variable.led11_toogle_flag = 0;
                no_storage.led_temp_variable.led11_push = 0;
                reback_led_sta(10);
            }
        }
        if (no_storage.led_temp_variable.led12_push == 1) {
            if (no_storage.led_temp_variable.led12_toogle_flag == 0) {
                Led_Duty[11] = 0;
                device_write(htr321x, &Led_Duty[11], HTR32xx_LED11, 1);
                no_storage.led_temp_variable.led12_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[11] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[11], HTR32xx_LED11, 1);
                no_storage.led_temp_variable.led12_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led12_blink_times++;
            }
            if (no_storage.led_temp_variable.led12_blink_times >= 8) {
                no_storage.led_temp_variable.led12_blink_times = 0;
                no_storage.led_temp_variable.led12_toogle_flag = 0;
                no_storage.led_temp_variable.led12_push = 0;
                reback_led_sta(11);
            }
        }
        if (no_storage.led_temp_variable.led13_push == 1) {
            if (no_storage.led_temp_variable.led13_toogle_flag == 0) {
                Led_Duty[12] = 0;
                device_write(htr321x, &Led_Duty[12], HTR32xx_LED12, 1);
                no_storage.led_temp_variable.led13_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[12] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[12], HTR32xx_LED12, 1);
                no_storage.led_temp_variable.led13_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led13_blink_times++;
            }
            if (no_storage.led_temp_variable.led13_blink_times >= 8) {
                no_storage.led_temp_variable.led13_blink_times = 0;
                no_storage.led_temp_variable.led13_toogle_flag = 0;
                no_storage.led_temp_variable.led13_push = 0;
                reback_led_sta(12);
            }
        }
        if (no_storage.led_temp_variable.led14_push == 1) {
            if (no_storage.led_temp_variable.led14_toogle_flag == 0) {
                Led_Duty[13] = 0;
                device_write(htr321x, &Led_Duty[13], HTR32xx_LED13, 1);
                no_storage.led_temp_variable.led14_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[13] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[13], HTR32xx_LED13, 1);
                no_storage.led_temp_variable.led14_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led14_blink_times++;
            }
            if (no_storage.led_temp_variable.led14_blink_times >= 8) {
                no_storage.led_temp_variable.led14_blink_times = 0;
                no_storage.led_temp_variable.led14_toogle_flag = 0;
                no_storage.led_temp_variable.led14_push = 0;
                reback_led_sta(13);
            }
        }
        if (no_storage.led_temp_variable.led15_push == 1) {
            if (no_storage.led_temp_variable.led15_toogle_flag == 0) {
                Led_Duty[14] = 0;
                device_write(htr321x, &Led_Duty[14], HTR32xx_LED14, 1);
                no_storage.led_temp_variable.led15_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[14] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[14], HTR32xx_LED14, 1);
                no_storage.led_temp_variable.led15_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led15_blink_times++;
            }
            if (no_storage.led_temp_variable.led15_blink_times >= 8) {
                no_storage.led_temp_variable.led15_blink_times = 0;
                no_storage.led_temp_variable.led15_toogle_flag = 0;
                no_storage.led_temp_variable.led15_push = 0;
                reback_led_sta(14);
            }
        }
        if (no_storage.led_temp_variable.led16_push == 1) {
            if (no_storage.led_temp_variable.led16_toogle_flag == 0) {
                Led_Duty[15] = 0;
                device_write(htr321x, &Led_Duty[15], HTR32xx_LED15, 1);
                no_storage.led_temp_variable.led16_toogle_flag = 1;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
            }
            else {
                Led_Duty[15] = die_ledmoded_ledvule;
                device_write(htr321x, &Led_Duty[15], HTR32xx_LED15, 1);
                no_storage.led_temp_variable.led16_toogle_flag = 0;
                device_ioctl(htr321x, IOCTL_HTR32xx_UPDATA, NULL);
                no_storage.led_temp_variable.led16_blink_times++;
            }
            if (no_storage.led_temp_variable.led16_blink_times >= 8) {
                no_storage.led_temp_variable.led16_blink_times = 0;
                no_storage.led_temp_variable.led16_toogle_flag = 0;
                no_storage.led_temp_variable.led16_push = 0;
                reback_led_sta(15);
            }
        }
    }
}
void app_htr3218_poll(void) {
    htr321x = resources_get("dev_htr3218");
    assert(htr321x);
    storage_led = (struct storage_led_struct*)storage_get(STORAGE_AREA_LIGHT_MODE);
    assert(storage_led);
    htr3218_ops.toggle_ms = 50;
    htr3218_ops.toggle_times = 5;
    /* create a timer for proc polling */
    proc_timer = soft_timer_create("htr3218_ProcTimer", SFTIM_MODE_REPEAT,
        __ms2ticks(62), NULL, _timer_expired);
    assert(proc_timer);
    soft_timer_start(proc_timer);
}